﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using EasyStudy.Logic;

namespace EasyStudy.UI
{
    public partial class FrmUpdateEbbTask : KryptonForm
    {
        private EbbinghausTask task;

        public FrmUpdateEbbTask()
        {
            InitializeComponent();

            msgBox.Icon = MessageBoxIcon.Question;
            msgBox.DefaultButton = TaskDialogButtons.Cancel;
            msgBox.CommonButtons = TaskDialogButtons.OK | TaskDialogButtons.Cancel;
            loadCategories();
        }

        public FrmUpdateEbbTask(EbbinghausTask task)
            : this()
        {
            this.task = task;
            this.txtSubject.Text = task.Subject;
            this.txtDescribe.Text = task.Comment;
            this.cmbType.Text = task.Type;
        }

        private void loadCategories()
        {
            cmbType.Text = "";
            cmbType.Items.Clear();
            cmbType.Items.AddRange(EbbTaskDBMgr.getAllCategories().ToArray());

            if (cmbType.Items.Count > 0)
            {
                cmbType.SelectedIndex = 0;
                cmbType.Select(0, 0);
            }
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            msgBox.Content = "主题：" + txtSubject.Text + "\r\n备注:" + txtDescribe.Text + "\r\n任务类型:" + cmbType.Text;
            msgBox.WindowTitle = "您确定要更新吗?此操作是不可撤销的哟~~";

            if (MessageBox.Show(msgBox.Content, msgBox.WindowTitle, 
                    MessageBoxButtons.OKCancel, 
                    MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
            //if (msgBox.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                EbbTaskDBMgr.UpdateATask(task.ID, txtSubject.Text, txtDescribe.Text, cmbType.Text);
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }
    }
}
